home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / tfmload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-05  |  2.7 KB  |  122 lines

  1. /*
  2.  *   Loads a tfm file.  It marks the characters as undefined.
  3.  */
  4. #include "structures.h" /* The copyright notice in that file is included too! */
  5. /*
  6.  *   These are the external routines it calls:
  7.  */
  8. extern void error() ;
  9. extern integer scalewidth() ;
  10. extern FILE *search() ;
  11. /*
  12.  *   Here are the external variables we use:
  13.  */
  14. extern real conv ;
  15. extern real alpha ;
  16. extern char *tfmpath ;
  17. extern char errbuf[] ;
  18. /*
  19.  *   Our static variables:
  20.  */
  21. static FILE *tfmfile ; 
  22. static char name[50] ;
  23.  
  24. /*
  25.  *   Tries to open a tfm file.  Aborts job if unsuccessful.
  26.  */
  27. void
  28. tfmopen(fd)
  29.         register fontdesctype *fd ;
  30. {
  31.    register char *d, *n ;
  32.  
  33.    d = fd->area ;
  34.    n = fd->name ;
  35.    if (*d==0)
  36.       d = tfmpath ;
  37.    (void)sprintf(name, "%s.tfm", n) ;
  38.    if ((tfmfile=search(d, name))==NULL) {
  39.       (void)sprintf(errbuf, "! Can't open font metric file %s%s",
  40.              fd->area, name) ;
  41.       error(errbuf) ;
  42.    }
  43. }
  44.  
  45. shalfword
  46. tfmbyte ()
  47. {
  48.   return(getc(tfmfile)) ;
  49. }
  50.  
  51. halfword
  52. tfm16 ()
  53. {
  54.   register halfword a ; 
  55.   a = tfmbyte () ; 
  56.   return ( a * 256 + tfmbyte () ) ; 
  57.  
  58. integer
  59. tfm32 ()
  60. {
  61.   register integer a ; 
  62.   a = tfm16 () ; 
  63.   if (a > 32767) a -= 65536 ;
  64.   return ( a * 65536 + tfm16 () ) ; 
  65.  
  66. void
  67. tfmload(curfnt)
  68.         register fontdesctype *curfnt ;
  69. {
  70.    register shalfword i ;
  71.    register integer li ;
  72.    integer scaledsize ;
  73.    shalfword nw, hd ;
  74.    shalfword bc, ec ;
  75.    integer scaled[256] ;
  76.    halfword chardat[256] ;
  77.  
  78.    tfmopen(curfnt) ;
  79. /*
  80.  *   Next, we read the font data from the tfm file, and store it in
  81.  *   our own arrays.
  82.  */
  83.    li = tfm16() ; hd = tfm16() ;
  84.    bc = tfm16() ; ec = tfm16() ;
  85.    nw = tfm16() ;
  86.    li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
  87.    li = tfm32() ;
  88.    if (li && curfnt->checksum)
  89.       if (li!=curfnt->checksum) {
  90.          (void)sprintf(errbuf,"Checksum mismatch in %s", name) ;
  91.          error(errbuf) ;
  92.        }
  93.    li = (integer)(alpha * (real)tfm32()) ;
  94.    if (li > curfnt->designsize + 2 || li < curfnt->designsize - 2) {
  95.       (void)sprintf(errbuf,"Design size mismatch in %s", name) ;
  96.       error(errbuf) ;
  97.    }
  98.    for (i=2; i<hd; i++)
  99.       li = tfm32() ;
  100.    for (i=0; i<256; i++)
  101.       chardat[i] = 256 ;
  102.    for (i=bc; i<=ec; i++) {
  103.       chardat[i] = tfmbyte() ;
  104.       li = tfm16() ;
  105.       li = tfmbyte() ;
  106.    }
  107.    scaledsize = curfnt->scaledsize ;
  108.    for (i=0; i<nw; i++)
  109.       scaled[i] = scalewidth(tfm32(), scaledsize) ;
  110.    (void)fclose(tfmfile) ;
  111.    for (i=0; i<256; i++)
  112.       if (chardat[i]!= 256) {
  113.          li = scaled[chardat[i]] ;
  114.          curfnt->chardesc[i].TFMwidth = li ;
  115.          curfnt->chardesc[i].pixelwidth = ((integer)(conv*li+0.5)) ;
  116.          curfnt->chardesc[i].flags = EXISTS ;
  117.       }
  118.    curfnt->loaded = 1 ;
  119. }
  120.